<?php

namespace App\Admin\Actions;

use App\Model\Order;
use Encore\Admin\Actions\RowAction;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class UpdateAddress extends RowAction
{
    public $name = '修改发货地址';

    protected $row;

    public function handle(Model $model,Request $request)
    {
        $this->row = $model;
        // $model ...
        $addressInfo = $request->get('address_info');
        $delivery_user = $request->get('delivery_user');
        $phone = $request['phone'];
        $orderInfo = Order::query()->where('id',$model->order_id)->first();
        if($addressInfo){
            $orderInfo->address_info = $addressInfo;
        }
        if($delivery_user){
            $orderInfo->delivery_user = $delivery_user;
        }
        if($phone){
            $orderInfo->phone = $delivery_user;
        }
        $orderInfo->save();

        return $this->response()->success('修改成功')->refresh();
    }

    public function form()
    {
        $this->html("<p>提示：值为空时，则代表不修改当前值</p>");
        $this->text('address_info', '收货地址')->value();
        $this->text('delivery_user', '收货人');
        $this->text('phone', '收货电话');
    }

}